package com.ruoyi.report.controller.report;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.report.domain.HanZaiBuyHouse;
import com.ruoyi.report.domain.HanZaiCustomerInfo;
import com.ruoyi.report.domain.HanZaiHouseInfo;
import com.ruoyi.report.service.HanZaiBuyHouseService;
import com.ruoyi.report.service.HanZaiCustomerInfoService;
import com.ruoyi.report.service.HanZaiEmailService;
import com.ruoyi.report.service.HanZaiHouseInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: 憨憨爱崽崽
 * Name: HanZaiTheSalesmanController 业务员报表Controller
 * Date: 2022/4/13
 * Time: 11:33
 **/
@RestController
@RequestMapping("/the_salesman")
public class HanZaiTheSalesmanController extends BaseController {
    @Autowired
    private HanZaiBuyHouseService buyHouseService;
    @Autowired
    private HanZaiCustomerInfoService customerInfoService;
    @Autowired
    private HanZaiEmailService emailService;
    @Autowired
    private HanZaiHouseInfoService houseInfoService;

    @RequestMapping("/salesman_list")
    public TableDataInfo getTheSalesmanList(HanZaiBuyHouse buyHouse){
        List<HanZaiBuyHouse> buyHouseList = buyHouseService.selectHanZaiBuyHouseList(buyHouse);
        for (HanZaiBuyHouse house : buyHouseList) {
            HanZaiCustomerInfo customerInfo = customerInfoService.selectCustomerInfoByCustid(Long.valueOf(house.getCustId()));
            HanZaiHouseInfo houseInfoOne = houseInfoService.selectHouseInfoByHouseId(Long.valueOf(house.getHourseId()));
            if (house.getHourseId2() !=null) {
                HanZaiHouseInfo houseInfoTow = houseInfoService.selectHouseInfoByHouseId(Long.valueOf(house.getHourseId2()));
                house.setHoursNameTow(houseInfoTow.getHouseName());
            }else{
                house.setHoursNameTow(houseInfoOne.getHouseName());
            }
            Date houseProcessTime = buyHouseService.selectBuyHouseProcessTime(house.getCustId());
            house.setCustName(customerInfo.getCustname());
            house.setHoursNameOne(houseInfoOne.getHouseName());
            if (houseProcessTime != null){
                String time = new SimpleDateFormat("yyyy-MM-dd").format(houseProcessTime);
                System.out.println(time);
                house.setPsTime(time);
            }else{
                house.setPsTime("未到账");
            }
        }
        return getDataTable(buyHouseList);
    }
}
